<?php
// namespace declaration: Core Templates
namespace teia\webdev\php\core;

// define variables with default values, if undefined
if (!isset($greeting_txt)) $greeting_txt = 'Hello, ';

if (!isset($account_txt)) $account_txt = 'My Account';
if (!isset($account_href)) $account_href = '/account.php';

if (!isset($login_txt)) $login_txt = 'Log-in | Sign-up';
if (!isset($login_href)) $login_href = '/login.php';

if (!isset($logout_txt)) $logout_txt = 'Log out';
if (!isset($logout_href)) $logout_href = '/logout.php';

// get user from session
$user = SessionWrapper::get_user();
?>

<div id="usr_nav_msg">
	<span class="nav_msg" id="nav_greeting_txt">
		<?php 
			echo trim($greeting_txt) .' '. $user->get_disp_name() . ".\n";
		?>
	</span>
	<?php
	if ($user->is_logged()) {		
		// the user is already logged in 
		// offer link to account
		echo "<span class=\"nav_msg\" id=\"nav_account_link\">\n<a href=\"$account_href\">$account_txt</a>\n</span>\n";
		// offer link to log out
		echo "<span class=\"nav_msg\" id=\"nav_logout_link\">\n<a href=\"$logout_href\">$logout_txt</a>\n</span>\n";
	} else {
		// the user is not logged in yet, offer link to log in
		echo "<span class=\"nav_msg\" id=\"nav_login_link\">\n<a href=\"$login_href\">$login_txt</a>\n</span>\n";
	}
	?>
</div>